1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.MediaFile;
26 
27 private import gio.FileIF;
28 private import gio.InputStream;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gtk.MediaStream;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 
36 
37 /**
38  * `GtkMediaFile` implements `GtkMediaStream` for files.
39  * 
40  * This provides a simple way to play back video files with GTK.
41  * 
42  * GTK provides a GIO extension point for `GtkMediaFile` implementations
43  * to allow for external implementations using various media frameworks.
44  * 
45  * GTK itself includes implementations using GStreamer and ffmpeg.
46  */
47 public class MediaFile : MediaStream
48 {
49 	/** the main Gtk struct */
50 	protected GtkMediaFile* gtkMediaFile;
51 
52 	/** Get the main Gtk struct */
53 	public GtkMediaFile* getMediaFileStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gtkMediaFile;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gtkMediaFile;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GtkMediaFile* gtkMediaFile, bool ownedRef = false)
70 	{
71 		this.gtkMediaFile = gtkMediaFile;
72 		super(cast(GtkMediaStream*)gtkMediaFile, ownedRef);
73 	}
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return gtk_media_file_get_type();
80 	}
81 
82 	/**
83 	 * Creates a new empty media file.
84 	 *
85 	 * Returns: a new `GtkMediaFile`
86 	 *
87 	 * Throws: ConstructionException GTK+ fails to create the object.
88 	 */
89 	public this()
90 	{
91 		auto __p = gtk_media_file_new();
92 
93 		if(__p is null)
94 		{
95 			throw new ConstructionException("null returned by new");
96 		}
97 
98 		this(cast(GtkMediaFile*) __p, true);
99 	}
100 
101 	/**
102 	 * Creates a new media file to play @file.
103 	 *
104 	 * Params:
105 	 *     file = The file to play
106 	 *
107 	 * Returns: a new `GtkMediaFile` playing @file
108 	 *
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this(FileIF file)
112 	{
113 		auto __p = gtk_media_file_new_for_file((file is null) ? null : file.getFileStruct());
114 
115 		if(__p is null)
116 		{
117 			throw new ConstructionException("null returned by new_for_file");
118 		}
119 
120 		this(cast(GtkMediaFile*) __p, true);
121 	}
122 
123 	/**
124 	 * Creates a new media file for the given filename.
125 	 *
126 	 * This is a utility function that converts the given @filename
127 	 * to a `GFile` and calls [ctor@Gtk.MediaFile.new_for_file].
128 	 *
129 	 * Params:
130 	 *     filename = filename to open
131 	 *
132 	 * Returns: a new `GtkMediaFile` playing @filename
133 	 *
134 	 * Throws: ConstructionException GTK+ fails to create the object.
135 	 */
136 	public this(string filename)
137 	{
138 		auto __p = gtk_media_file_new_for_filename(Str.toStringz(filename));
139 
140 		if(__p is null)
141 		{
142 			throw new ConstructionException("null returned by new_for_filename");
143 		}
144 
145 		this(cast(GtkMediaFile*) __p, true);
146 	}
147 
148 	/**
149 	 * Creates a new media file to play @stream.
150 	 *
151 	 * If you want the resulting media to be seekable,
152 	 * the stream should implement the `GSeekable` interface.
153 	 *
154 	 * Params:
155 	 *     stream = The stream to play
156 	 *
157 	 * Returns: a new `GtkMediaFile`
158 	 *
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this(InputStream stream)
162 	{
163 		auto __p = gtk_media_file_new_for_input_stream((stream is null) ? null : stream.getInputStreamStruct());
164 
165 		if(__p is null)
166 		{
167 			throw new ConstructionException("null returned by new_for_input_stream");
168 		}
169 
170 		this(cast(GtkMediaFile*) __p, true);
171 	}
172 
173 	/**
174 	 * Resets the media file to be empty.
175 	 */
176 	public void clear()
177 	{
178 		gtk_media_file_clear(gtkMediaFile);
179 	}
180 
181 	/**
182 	 * Returns the file that @self is currently playing from.
183 	 *
184 	 * When @self is not playing or not playing from a file,
185 	 * %NULL is returned.
186 	 *
187 	 * Returns: The currently playing file
188 	 */
189 	public FileIF getFile()
190 	{
191 		auto __p = gtk_media_file_get_file(gtkMediaFile);
192 
193 		if(__p is null)
194 		{
195 			return null;
196 		}
197 
198 		return ObjectG.getDObject!(FileIF)(cast(GFile*) __p);
199 	}
200 
201 	/**
202 	 * Returns the stream that @self is currently playing from.
203 	 *
204 	 * When @self is not playing or not playing from a stream,
205 	 * %NULL is returned.
206 	 *
207 	 * Returns: The currently playing stream
208 	 */
209 	public InputStream getInputStream()
210 	{
211 		auto __p = gtk_media_file_get_input_stream(gtkMediaFile);
212 
213 		if(__p is null)
214 		{
215 			return null;
216 		}
217 
218 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p);
219 	}
220 
221 	/**
222 	 * Sets the `GtkMediaFile` to play the given file.
223 	 *
224 	 * If any file is still playing, stop playing it.
225 	 *
226 	 * Params:
227 	 *     file = the file to play
228 	 */
229 	public void setFile(FileIF file)
230 	{
231 		gtk_media_file_set_file(gtkMediaFile, (file is null) ? null : file.getFileStruct());
232 	}
233 
234 	/**
235 	 * Sets the `GtkMediaFile to play the given file.
236 	 *
237 	 * This is a utility function that converts the given @filename
238 	 * to a `GFile` and calls [method@Gtk.MediaFile.set_file].
239 	 *
240 	 * Params:
241 	 *     filename = name of file to play
242 	 */
243 	public void setFilename(string filename)
244 	{
245 		gtk_media_file_set_filename(gtkMediaFile, Str.toStringz(filename));
246 	}
247 
248 	/**
249 	 * Sets the `GtkMediaFile` to play the given stream.
250 	 *
251 	 * If anything is still playing, stop playing it.
252 	 *
253 	 * Full control about the @stream is assumed for the duration of
254 	 * playback. The stream will not be closed.
255 	 *
256 	 * Params:
257 	 *     stream = the stream to play from
258 	 */
259 	public void setInputStream(InputStream stream)
260 	{
261 		gtk_media_file_set_input_stream(gtkMediaFile, (stream is null) ? null : stream.getInputStreamStruct());
262 	}
263 
264 	/**
265 	 * Sets the `GtkMediaFile to play the given resource.
266 	 *
267 	 * This is a utility function that converts the given @resource_path
268 	 * to a `GFile` and calls [method@Gtk.MediaFile.set_file].
269 	 *
270 	 * Params:
271 	 *     resourcePath = path to resource to play
272 	 */
273 	public void setResource(string resourcePath)
274 	{
275 		gtk_media_file_set_resource(gtkMediaFile, Str.toStringz(resourcePath));
276 	}
277 }